package com.foreknow.service.impl;


import com.foreknow.dao.impl.GuestbookDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.service.GuestbookService;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class GuestbookServiceImpl implements GuestbookService {
    @Override
    public List<Object> getQueryAll() {
        DBManager dbManager = DBManager.getInstance();
        Connection connection = dbManager.getConnection();
        GuestbookDaoImpl dao = new GuestbookDaoImpl();
        dao.setConnection(connection);
        List<Object> list = dao.getQueryAll();
        return list;
    }

    @Override
    public boolean delete(int id) {
        DBManager dbManager = DBManager.getInstance();
        Connection conn = dbManager.getConnection();
        GuestbookDaoImpl guestDao = new GuestbookDaoImpl();
        guestDao.setConnection(conn);
        boolean isRight = false;

        try {
            isRight = guestDao.delete(id);
            conn.commit();
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }


        return isRight;
    }

    public static void main(String[] args) {
        GuestbookService service = new GuestbookServiceImpl();
        boolean isRight = service.delete(2);
        System.out.println(isRight);
    }
}
